﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_DSQuangCao : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private void MessageBox(string msg)
    {
        Page.Controls.Add(new LiteralControl(
        "<script language='javascript'> window.alert('" + msg.Replace("'", "\\'") + "');location.href='DSQuangCao.aspx';</script>"));

    }
    protected void lkbtnThem_Click(object sender, EventArgs e)
    {
        QuangCaoBUS objQuangCao = 
            new QuangCaoBUS(TGDDConfiguration.DbConnectionString);
        QuangCaoDTO qcDto = new QuangCaoDTO();
        qcDto.ViTri = int.Parse(lstViTri.SelectedValue.ToString());
        qcDto.HinhMinhHoa = fileUploadHinhAnh.FileName;
        qcDto.Gia = long.Parse(txtGia.Text);
        qcDto.TenKhachHang = txtTenKhachHang.Text;
        qcDto.WebSite = txtWebsite.Text;
        qcDto.NgayBatDau = DateTime.Parse(txtNgayBatDau.Text);
        qcDto.NgayKetThuc = DateTime.Parse(txtNgayKetThuc.Text);

        if (objQuangCao.InsertQuangCao(qcDto))
        {
            string strBaseLocation = Server.MapPath("..") + "\\images\\quangcao\\" + fileUploadHinhAnh.FileName;

            if (fileUploadHinhAnh.PostedFile != null )
            {
                fileUploadHinhAnh.PostedFile.SaveAs(strBaseLocation);
            }

            MessageBox("Thêm thành công");
        }
        else
        {
            MessageBox("Thêm thất bại");
        }
    }
}
